class GameScene extends Phaser.Scene {
    constructor() {
        super('GameScene');
    }

    create() {
        // 初始化游戏状态
        this.score = 0;
        this.gameOver = false;
        this.energy = 100;  // 初始能量值
        this.maxEnergy = 100;  // 最大能量值
        this.energyRegenRate = 0.2;  // 提高能量恢复速率
        this.shootEnergyCost = 2;  // 降低射击能量消耗
        
        // 添加武器系统
        this.weaponLevel = 1;  // 初始武器等级
        this.weaponConfigs = {
            1: { 
                bulletCount: 1, 
                spread: 0, 
                damage: 1,
                scale: 0.5,
                tint: 0xffffff
            },
            2: { 
                bulletCount: 2, 
                spread: 15, 
                damage: 1,
                scale: 0.6,
                tint: 0x00ff00
            },
            3: { 
                bulletCount: 3, 
                spread: 20, 
                damage: 1,
                scale: 0.7,
                tint: 0x00ffff
            },
            4: { 
                bulletCount: 3, 
                spread: 25, 
                damage: 2,
                scale: 0.8,
                tint: 0xff00ff
            },
            5: { 
                bulletCount: 5, 
                spread: 30, 
                damage: 2,
                scale: 0.9,
                tint: 0xffff00
            }
        };

        // 创建背景
        this.background = this.add.tileSprite(0, 0, this.game.config.width, this.game.config.height, 'background')
            .setOrigin(0, 0);

        // 创建爆炸粒子纹理 - 优化为更小的圆形
        const graphics = this.make.graphics({ x: 0, y: 0, add: false });
        graphics.fillStyle(0xffffff);
        graphics.fillCircle(2, 2, 2);  // 更小的圆形
        graphics.generateTexture('explosion', 4, 4);

        // 创建爆炸烟雾纹理 - 优化为更柔和的圆形
        const smokeGraphics = this.make.graphics({ x: 0, y: 0, add: false });
        smokeGraphics.fillStyle(0xffffff);
        smokeGraphics.fillCircle(6, 6, 6);  // 更柔和的圆形
        smokeGraphics.generateTexture('smoke', 12, 12);

        // 创建爆炸碎片纹理 - 优化为更小的圆形
        const debrisGraphics = this.make.graphics({ x: 0, y: 0, add: false });
        debrisGraphics.fillStyle(0xffffff);
        debrisGraphics.fillCircle(2, 2, 2);  // 更小的圆形
        debrisGraphics.generateTexture('debris', 4, 4);

        // 创建火花纹理 - 新增
        const sparkGraphics = this.make.graphics({ x: 0, y: 0, add: false });
        sparkGraphics.fillStyle(0xffffff);
        sparkGraphics.fillCircle(1, 1, 1);  // 最小的圆形
        sparkGraphics.generateTexture('spark', 2, 2);

        // 创建玩家
        this.player = this.physics.add.sprite(this.game.config.width / 2, this.game.config.height - 100, 'player');
        this.player.setCollideWorldBounds(true);
        this.updatePlayerAppearance();  // 初始化玩家外观
        this.player.setDepth(1);

        // 创建能量条背景
        this.energyBarBg = this.add.rectangle(10, 70, 200, 10, 0x000000, 0.5)
            .setOrigin(0, 0)
            .setScrollFactor(0);

        // 创建能量条
        this.energyBar = this.add.rectangle(10, 70, 200, 10, 0x00ff00)
            .setOrigin(0, 0)
            .setScrollFactor(0);

        // 创建能量文本
        this.energyText = this.add.text(220, 65, '能量: 100%', {
            fontSize: '14px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 5, y: 2 }
        }).setScrollFactor(0);

        // 创建子弹组
        this.bullets = this.physics.add.group({
            defaultKey: 'bullet'
        });

        // 创建敌机组
        this.enemies = this.physics.add.group({
            defaultKey: 'enemy1'
        });

        // 敌机类型配置
        this.enemyTypes = [
            {
                key: 'enemy1',
                speed: 100,
                health: 1,
                score: 100,
                scale: 0.5
            },
            {
                key: 'enemy2',
                speed: 150,
                health: 2,
                score: 200,
                scale: 0.4
            },
            {
                key: 'enemy3',
                speed: 80,
                health: 3,
                score: 300,
                scale: 0.6
            }
        ];

        // 创建爆炸粒子系统
        this.explosions = this.add.group();
        this.createExplosionEmitter();

        // 设置碰撞
        this.physics.add.collider(this.bullets, this.enemies, this.hitEnemy, null, this);
        this.physics.add.collider(this.player, this.enemies, this.hitPlayer, null, this);

        // 创建分数文本
        this.scoreText = this.add.text(10, 10, '分数: 0', {
            fontSize: '20px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 5, y: 5 }
        }).setScrollFactor(0);

        // 设置输入
        this.cursors = this.input.keyboard.createCursorKeys();
        
        // 设置触摸输入
        this.input.on('pointermove', (pointer) => {
            if (pointer.isDown) {
                // 更新为同时支持X和Y轴移动
                this.player.x = Phaser.Math.Clamp(pointer.x, 0, this.game.config.width);
                this.player.y = Phaser.Math.Clamp(pointer.y, 0, this.game.config.height);
            }
        });

        // 开始生成敌人
        this.time.addEvent({
            delay: 1500,
            callback: this.spawnEnemy,
            callbackScope: this,
            loop: true
        });

        // 设置自动射击
        this.time.addEvent({
            delay: 300,  // 降低射击频率
            callback: this.shoot,
            callbackScope: this,
            loop: true
        });

        // 添加能量恢复定时器
        this.time.addEvent({
            delay: 100,
            callback: this.regenerateEnergy,
            callbackScope: this,
            loop: true
        });

        // 添加游戏说明
        this.add.text(10, 40, '使用方向键或触摸移动', {
            fontSize: '14px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 5, y: 5 }
        }).setScrollFactor(0);

        // 设置子弹超出屏幕的回收
        this.bullets.children.iterate((bullet) => {
            bullet.checkWorldBounds = true;
            bullet.outOfBoundsKill = true;
        });

        // 创建道具组
        this.powerups = this.physics.add.group({
            defaultKey: 'powerup'
        });

        // 设置道具碰撞
        this.physics.add.overlap(this.player, this.powerups, this.collectPowerup, null, this);

        // 开始生成道具
        this.time.addEvent({
            delay: 10000,  // 每10秒生成一个道具
            callback: this.spawnPowerup,
            callbackScope: this,
            loop: true
        });

        // 创建武器等级文本
        this.weaponText = this.add.text(10, 100, '武器等级: 1', {
            fontSize: '16px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 5, y: 5 }
        }).setScrollFactor(0);

        // 创建音效
        this.createSoundEffects();
    }

    createExplosionEmitter() {
        // 创建爆炸粒子发射器
        this.explosionEmitter = this.add.particles(0, 0, 'explosion', {  // 使用explosion纹理替代bullet
            speed: { min: 50, max: 100 },
            angle: { min: 0, max: 360 },
            scale: { start: 1, end: 0 },
            lifespan: 500,
            quantity: 20,
            emitting: false,
            frequency: -1,
            blendMode: 'ADD',
            alpha: { start: 1, end: 0 },
            tint: [0xff4400, 0xff8800, 0xffaa00]  // 添加颜色变化
        });
    }

    createExplosion(x, y, isBig = false) {
        // 创建爆炸组
        const explosionGroup = this.add.group();

        // 创建爆炸烟雾 - 优化烟雾效果
        const smokeParticles = this.add.particles(x, y, 'smoke');
        const smokeEmitter = smokeParticles.createEmitter({
            speed: { min: 30, max: 80 },
            angle: { min: 0, max: 360 },
            scale: { start: 0.8, end: 3 },
            lifespan: isBig ? 1500 : 800,
            quantity: isBig ? 25 : 12,
            emitting: false,
            alpha: { start: 0.6, end: 0 },
            tint: [0x666666, 0x999999, 0xcccccc, 0x888888],
            rotate: { min: 0, max: 360 },
            gravityY: -50,
            frequency: 50,
            blendMode: 'ADD'
        });

        // 创建爆炸火焰 - 优化火焰效果
        const fireParticles = this.add.particles(x, y, 'explosion');
        const fireEmitter = fireParticles.createEmitter({
            speed: { min: 80, max: 200 },
            angle: { min: 0, max: 360 },
            scale: { start: 1.5, end: 0 },
            lifespan: isBig ? 600 : 300,
            quantity: isBig ? 30 : 15,
            emitting: false,
            alpha: { start: 1, end: 0 },
            tint: [0xff4400, 0xff8800, 0xffaa00, 0xff6600, 0xff2200],
            rotate: { min: 0, max: 360 },
            frequency: 30,
            blendMode: 'ADD'
        });

        // 创建爆炸碎片 - 优化碎片效果
        const debrisParticles = this.add.particles(x, y, 'debris');
        const debrisEmitter = debrisParticles.createEmitter({
            speed: { min: 150, max: 300 },
            angle: { min: 0, max: 360 },
            scale: { start: 1.2, end: 0.6 },
            lifespan: isBig ? 1200 : 600,
            quantity: isBig ? 20 : 10,
            emitting: false,
            alpha: { start: 0.8, end: 0 },
            rotate: { min: 0, max: 360 },
            gravityY: 500,
            frequency: 40,
            blendMode: 'ADD',
            tint: [0xcccccc, 0x999999, 0x666666]
        });

        // 创建爆炸火花 - 使用新的火花纹理
        const sparkParticles = this.add.particles(x, y, 'spark');
        const sparkEmitter = sparkParticles.createEmitter({
            speed: { min: 100, max: 250 },
            angle: { min: 0, max: 360 },
            scale: { start: 0.5, end: 0 },
            lifespan: isBig ? 400 : 200,
            quantity: isBig ? 15 : 8,
            emitting: false,
            alpha: { start: 1, end: 0 },
            tint: [0xffff00, 0xffaa00, 0xff8800],
            rotate: { min: 0, max: 360 },
            frequency: 20,
            blendMode: 'ADD'
        });

        // 创建爆炸光晕 - 优化光晕效果
        const glow = this.add.circle(x, y, isBig ? 60 : 30, 0xffffff);
        glow.setBlendMode(Phaser.BlendModes.ADD);
        
        // 添加光晕动画
        this.tweens.add({
            targets: glow,
            radius: isBig ? 150 : 75,
            alpha: 0,
            duration: isBig ? 400 : 200,
            ease: 'Cubic.easeOut',
            onComplete: () => glow.destroy()
        });

        // 创建爆炸冲击波
        const shockwave = this.add.circle(x, y, 0, 0xffffff);
        shockwave.setBlendMode(Phaser.BlendModes.ADD);
        shockwave.setStrokeStyle(2, 0xffffff, 0.8);
        
        // 添加冲击波动画
        this.tweens.add({
            targets: shockwave,
            radius: isBig ? 200 : 100,
            alpha: 0,
            duration: isBig ? 500 : 250,
            ease: 'Cubic.easeOut',
            onComplete: () => shockwave.destroy()
        });

        // 发射所有效果
        smokeEmitter.explode(isBig ? 25 : 12, x, y);
        fireEmitter.explode(isBig ? 30 : 15, x, y);
        debrisEmitter.explode(isBig ? 20 : 10, x, y);
        sparkEmitter.explode(isBig ? 15 : 8, x, y);

        // 添加爆炸震动效果
        this.cameras.main.shake(isBig ? 400 : 200, isBig ? 0.008 : 0.004, true);

        // 延迟销毁粒子系统
        this.time.delayedCall(isBig ? 1500 : 800, () => {
            smokeParticles.destroy();
            fireParticles.destroy();
            debrisParticles.destroy();
            sparkParticles.destroy();
        });
    }

    update() {
        if (this.gameOver) return;

        // 移动背景
        this.background.tilePositionY -= 1;

        // 键盘控制
        if (this.cursors.left.isDown) {
            this.player.setVelocityX(-200);
        } else if (this.cursors.right.isDown) {
            this.player.setVelocityX(200);
        } else {
            this.player.setVelocityX(0);
        }

        // 添加上下移动控制
        if (this.cursors.up.isDown) {
            this.player.setVelocityY(-200);
        } else if (this.cursors.down.isDown) {
            this.player.setVelocityY(200);
        } else {
            this.player.setVelocityY(0);
        }

        // 限制战机在屏幕范围内
        this.player.x = Phaser.Math.Clamp(this.player.x, 0, this.game.config.width);
        this.player.y = Phaser.Math.Clamp(this.player.y, 0, this.game.config.height);
    }

    shoot() {
        if (this.gameOver || this.energy < this.shootEnergyCost) return;
        
        // 消耗能量
        this.energy = Math.max(0, this.energy - this.shootEnergyCost);
        this.updateEnergyBar();
        
        // 获取当前武器配置
        const weaponConfig = this.weaponConfigs[this.weaponLevel];
        
        // 创建多个子弹
        for (let i = 0; i < weaponConfig.bulletCount; i++) {
            const bullet = this.bullets.create(this.player.x, this.player.y - 20, 'bullet');
            bullet.setVelocityY(-400);
            
            // 设置子弹伤害
            bullet.damage = weaponConfig.damage;
            
            // 计算子弹角度
            if (weaponConfig.bulletCount > 1) {
                const angle = (i - (weaponConfig.bulletCount - 1) / 2) * weaponConfig.spread;
                bullet.setRotation(Phaser.Math.DegToRad(angle));
                const velocity = this.physics.velocityFromRotation(
                    Phaser.Math.DegToRad(angle - 90),
                    400
                );
                bullet.setVelocity(velocity.x, velocity.y);
            }
        }
    }

    regenerateEnergy() {
        if (this.gameOver) return;
        
        // 恢复能量
        this.energy = Math.min(this.maxEnergy, this.energy + this.energyRegenRate);
        this.updateEnergyBar();
    }

    updateEnergyBar() {
        // 更新能量条宽度
        const energyPercent = this.energy / this.maxEnergy;
        this.energyBar.width = 200 * energyPercent;
        
        // 更新能量条颜色
        if (energyPercent > 0.6) {
            this.energyBar.fillColor = 0x00ff00;  // 绿色
        } else if (energyPercent > 0.3) {
            this.energyBar.fillColor = 0xffff00;  // 黄色
        } else {
            this.energyBar.fillColor = 0xff0000;  // 红色
        }
        
        // 更新能量文本
        this.energyText.setText(`能量: ${Math.floor(this.energy)}%`);
    }

    spawnEnemy() {
        // 随机选择敌机类型
        const enemyType = this.enemyTypes[Phaser.Math.Between(0, this.enemyTypes.length - 1)];
        const x = Phaser.Math.Between(0, this.game.config.width);
        
        // 创建敌机
        const enemy = this.enemies.get(x, -30, enemyType.key);
        if (enemy) {
            enemy.setActive(true);
            enemy.setVisible(true);
            enemy.setVelocityY(enemyType.speed);
            enemy.setScale(enemyType.scale);
            
            // 添加敌机属性
            enemy.health = enemyType.health;
            enemy.score = enemyType.score;
        }
    }

    hitEnemy(bullet, enemy) {
        // 减少敌机生命值
        enemy.health -= bullet.damage || 1;
        
        // 如果敌机还有生命值，只创建小型爆炸效果
        if (enemy.health > 0) {
            this.createExplosion(enemy.x, enemy.y, false);
            this.sounds.hit();  // 播放击中音效
            
            // 增加少量能量
            this.energy = Math.min(this.maxEnergy, this.energy + 5);
            this.updateEnergyBar();
            bullet.setActive(false);
            bullet.setVisible(false);
            return;
        }
        
        // 敌机被摧毁，创建大型爆炸效果
        this.createExplosion(enemy.x, enemy.y, true);
        this.sounds.explosion();  // 播放爆炸音效
        
        bullet.setActive(false);
        bullet.setVisible(false);
        enemy.setActive(false);
        enemy.setVisible(false);
        
        // 增加分数和能量
        this.score += enemy.score;
        this.energy = Math.min(this.maxEnergy, this.energy + 15);
        this.updateEnergyBar();
        this.scoreText.setText('分数: ' + this.score);
    }

    hitPlayer(player, enemy) {
        // 创建爆炸效果
        this.createExplosion(player.x, player.y, true);
        this.sounds.gameOver();  // 播放游戏结束音效
        
        this.gameOver = true;
        this.physics.pause();

        // 创建半透明背景
        const overlay = this.add.rectangle(0, 0, this.game.config.width, this.game.config.height, 0x000000, 0.7)
            .setOrigin(0)
            .setScrollFactor(0);

        // 游戏结束文本
        this.add.text(this.game.config.width / 2, this.game.config.height / 2 - 50, '游戏结束!', {
            fontSize: '48px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 20, y: 10 }
        }).setOrigin(0.5);

        // 显示最终分数
        this.add.text(this.game.config.width / 2, this.game.config.height / 2 + 20, `最终分数: ${this.score}`, {
            fontSize: '32px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 20, y: 10 }
        }).setOrigin(0.5);

        // 重新开始按钮
        const restartButton = this.add.text(this.game.config.width / 2, this.game.config.height / 2 + 100, '重新开始', {
            fontSize: '32px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#4CAF50',
            padding: { x: 20, y: 10 }
        })
        .setOrigin(0.5)
        .setInteractive()
        .on('pointerover', () => restartButton.setStyle({ fill: '#ff0' }))
        .on('pointerout', () => restartButton.setStyle({ fill: '#fff' }))
        .on('pointerdown', () => this.scene.restart());

        // 返回主菜单按钮
        const menuButton = this.add.text(this.game.config.width / 2, this.game.config.height / 2 + 170, '返回主菜单', {
            fontSize: '32px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#2196F3',
            padding: { x: 20, y: 10 }
        })
        .setOrigin(0.5)
        .setInteractive()
        .on('pointerover', () => menuButton.setStyle({ fill: '#ff0' }))
        .on('pointerout', () => menuButton.setStyle({ fill: '#fff' }))
        .on('pointerdown', () => this.scene.start('MenuScene'));
    }

    spawnPowerup() {
        if (this.gameOver) return;

        // 随机选择道具类型
        const powerupType = Phaser.Math.Between(0, 3);  // 0: 能量恢复, 1: 能量上限, 2: 射击速度, 3: 武器升级
        const x = Phaser.Math.Between(50, this.game.config.width - 50);
        
        // 创建道具
        const powerup = this.powerups.create(x, -30, 'powerup');
        powerup.setActive(true);
        powerup.setVisible(true);
        powerup.setVelocityY(100);  // 下落速度
        powerup.setScale(0.8);
        
        // 添加道具属性
        powerup.type = powerupType;
        
        // 根据道具类型设置颜色
        switch(powerupType) {
            case 0:  // 能量恢复
                powerup.setTint(0x00ff00);  // 绿色
                break;
            case 1:  // 能量上限
                powerup.setTint(0x0000ff);  // 蓝色
                break;
            case 2:  // 射击速度
                powerup.setTint(0xffff00);  // 黄色
                break;
            case 3:  // 武器升级
                powerup.setTint(0xff00ff);  // 紫色
                break;
        }
        
        // 添加旋转动画
        this.tweens.add({
            targets: powerup,
            angle: 360,
            duration: 3000,
            repeat: -1
        });
    }

    collectPowerup(player, powerup) {
        // 播放收集道具音效
        this.sounds.powerup();
        
        // 根据道具类型应用效果
        switch(powerup.type) {
            case 0:  // 能量恢复
                this.energy = Math.min(this.maxEnergy, this.energy + 30);
                this.createFloatingText(powerup.x, powerup.y, '+30 能量');
                break;
            case 1:  // 能量上限
                this.maxEnergy = Math.min(200, this.maxEnergy + 20);
                this.energy = Math.min(this.maxEnergy, this.energy + 20);
                this.createFloatingText(powerup.x, powerup.y, '+20 能量上限');
                break;
            case 2:  // 射击速度
                this.shootEnergyCost = Math.max(1, this.shootEnergyCost - 0.5);
                this.createFloatingText(powerup.x, powerup.y, '射击消耗-0.5');
                break;
            case 3:  // 武器升级
                if (this.weaponLevel < 5) {
                    this.weaponLevel++;
                    this.createFloatingText(powerup.x, powerup.y, '武器升级!');
                    this.weaponText.setText(`武器等级: ${this.weaponLevel}`);
                    this.updatePlayerAppearance();  // 更新玩家外观
                } else {
                    this.createFloatingText(powerup.x, powerup.y, '武器已满级!');
                }
                break;
        }
        
        // 更新能量条
        this.updateEnergyBar();
        
        // 移除道具
        powerup.destroy();
    }

    createFloatingText(x, y, text) {
        const floatingText = this.add.text(x, y, text, {
            fontSize: '16px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 5, y: 5 }
        });
        
        // 添加浮动动画
        this.tweens.add({
            targets: floatingText,
            y: y - 50,
            alpha: 0,
            duration: 1000,
            onComplete: () => floatingText.destroy()
        });
    }

    createSoundEffects() {
        // 创建音频上下文
        const audioContext = new (window.AudioContext || window.webkitAudioContext)();
        
        // 创建音效生成函数
        const createBeep = (frequency, duration, volume = 0.3) => {
            const oscillator = audioContext.createOscillator();
            const gainNode = audioContext.createGain();
            
            oscillator.type = 'sine';
            oscillator.frequency.value = frequency;
            gainNode.gain.value = volume;
            
            oscillator.connect(gainNode);
            gainNode.connect(audioContext.destination);
            
            oscillator.start();
            setTimeout(() => {
                oscillator.stop();
            }, duration);
        };

        // 初始化音效对象
        this.sounds = {
            shoot: () => createBeep(880, 100, 0.3),
            explosion: () => createBeep(220, 300, 0.4),
            powerup: () => createBeep(440, 200, 0.5),
            gameOver: () => createBeep(110, 500, 0.6),
            hit: () => createBeep(330, 150, 0.3)
        };
    }

    updatePlayerAppearance() {
        const config = this.weaponConfigs[this.weaponLevel];
        
        // 更新玩家大小
        this.player.setScale(config.scale);
        
        // 更新玩家颜色
        this.player.setTint(config.tint);
        
        // 添加升级特效
        this.createUpgradeEffect();
    }

    createUpgradeEffect() {
        // 创建升级光环
        const glow = this.add.circle(this.player.x, this.player.y, this.player.width * 0.8, 0xffffff);
        glow.setBlendMode(Phaser.BlendModes.ADD);
        
        // 添加光环动画
        this.tweens.add({
            targets: glow,
            radius: this.player.width * 1.2,
            alpha: 0,
            duration: 500,
            ease: 'Cubic.easeOut',
            onComplete: () => glow.destroy()
        });

        // 创建粒子效果
        const particles = this.add.particles(this.player.x, this.player.y, 'explosion', {
            speed: { min: 50, max: 100 },
            angle: { min: 0, max: 360 },
            scale: { start: 0.5, end: 0 },
            lifespan: 500,
            quantity: 20,
            emitting: false,
            frequency: -1,
            blendMode: 'ADD',
            alpha: { start: 1, end: 0 },
            tint: this.weaponConfigs[this.weaponLevel].tint
        });

        // 创建发射器
        const emitter = particles.createEmitter({
            speed: { min: 50, max: 100 },
            angle: { min: 0, max: 360 },
            scale: { start: 0.5, end: 0 },
            lifespan: 500,
            quantity: 20,
            emitting: false,
            frequency: -1,
            blendMode: 'ADD',
            alpha: { start: 1, end: 0 },
            tint: this.weaponConfigs[this.weaponLevel].tint
        });

        // 发射粒子
        emitter.explode(20, this.player.x, this.player.y);
        
        // 延迟销毁粒子系统
        this.time.delayedCall(500, () => {
            particles.destroy();
        });
    }

    preload() {
        // 创建爆炸粒子纹理
        const graphics = this.make.graphics({ x: 0, y: 0, add: false });
        graphics.fillStyle(0xffffff);
        graphics.fillCircle(2, 2, 2);
        graphics.generateTexture('explosion', 4, 4);
    }
} 